home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4484 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: informatik.tu-muenchen.de!fischerj
  2. From: fischerj@informatik.tu-muenchen.de (Juergen "Rally" Fischer)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Random Number Generation
  5. Date: 29 Feb 1996 13:12:12 GMT
  6. Organization: Technische Universitaet Muenchen, Germany
  7. Distribution: world
  8. Message-ID: <4h48nc$jpu@sunsystem5.informatik.tu-muenchen.de>
  9. References: <199602071623.QAA00075@sable.ox.ac.uk> <Pine.OSF.3.91.960207175121.20357B-100000@hai.hiMolde.no>   <19960207.41F660.11A72@aj050.du.pipex.com> <1100.6613T1273T666@himolde.no>  <692.6619T1254T1752@in.net> <4g2bi9$1fls@rs18.hrz.th-darmstadt.de> <19960220.7D62838.7EC3@mojaveg.ridgecrest.ca.us> <2108.6624T1432T2901@cs.ruu.nl>
  10. NNTP-Posting-Host: hphalle2i.informatik.tu-muenchen.de
  11. Originator: fischerj@hphalle2i.informatik.tu-muenchen.de
  12.  
  13.  
  14. In article <2108.6624T1432T2901@cs.ruu.nl>, wsldanke@cs.ruu.nl (Wessel Dankers) writes:
  15. |> >> #include <stdlib.h>
  16. |> >> ....
  17. |> >>    num = ( (float) rand() / 32767E0 ) * ( high - low ) + low;
  18. |> 
  19. |> >In theory, this is a very good suggestion.  In practice, rand() is a
  20. |> >very poor RNG.  Run any common statistical tests on rand()'s output
  21. |> >to see.
  22. |> 
  23. |> What's wrong with FastRand()?
  24. |> 
  25. |> From a totally unexpected corner I got this article, which, amongst a lot of
  26. |> stuff about why god doesn't exist, contained the following algorithm as an
  27. |> *example*, so I don't know how good it is. (layout slightly changed by me).
  28.  
  29. AFAIK very good. I have tested such a "shift and eor" years ago, and
  30. it was good enough to generate .... what's the word for the thing a
  31. TV does if there's no channel ? :)
  32. Well, the function does it both for gfx and sound.
  33.  
  34. float. naaaaah.
  35.  
  36. |> 
  37. |> --
  38. |> From: PAGAN <pagan@delphi.com>
  39. |> Subject: Re: Atheism; the perfect antidote to poetry and style.
  40. |> Date: Sat, 10 Feb 96 04:15:01
  41. |> Newsgroups: alt.atheism.moderated
  42. |> 
  43. |> /*********************************************************************
  44. |>  RANDOM number generator
  45. |>      returns a random number from one to the value passed
  46. |>      repeat rate OTO 1e6
  47. |> *********************************************************************/
  48. |> int random(int val)
  49. |> { int num;                        /* this is what will be returned */
  50. |>   int bit0, bit1, bit14;
  51. |>   static int rndval=2;            /* seed value */
  52. |> 
  53. |>   if(val<0)                       /* if a negative value passed */
  54. |>       rndval=-val;                /* reseed */
  55. |> 
  56. |>   bit0 = rndval & 1;
  57. |>   bit1 = (rndval & 2) >> 1;
  58. |>   bit14 = bit0 ^ bit1;
  59. |>   rndval >>= 1;
  60. |>   rndval  |= bit14 << 14;
  61. |> 
  62. |>   num = rndval % val;
  63.  
  64. huh ? a div ? I sugesst to get it run without div.
  65.  
  66. |>   return num ? num : val;
  67. |> }
  68. |> 
  69. |> /*********************************************************************
  70. |>  SEED the RANDOM number generator
  71. |>      random number seed for the above
  72. |> *********************************************************************/
  73. |> seedrandom()               /* negative value to seed the generator */
  74. |> { random(-systemticks());  /* seed with system tick count */
  75. |> }
  76. |> --
  77. |> 
  78. |> 
  79. |> --
  80. |> Wessel Dankers                 _\\|//_            <wsldanke@cs.ruu.nl>
  81. |>                                ///|\\\
  82. |> ----------------------------oOO--(_)---OOo----------------------------
  83. |> `Never imagine yourself not to be otherwise than what it might appear
  84. |> to others that what you were or might have been was not otherwise than
  85. |> what you had been would have appeared to them to be otherwise.'
  86. |> 
  87.